//
//  JZChargeHomeCell.m
//  JFTwxsd
//
//  Created by Peter on 2018/4/10.
//  Copyright © 2018年 junfeiweiyejiaoyujituan. All rights reserved.
//

#import "JZChargeHomeCell.h"

@interface  JZChargeHomeCell()

@property (weak, nonatomic) IBOutlet UILabel *topLab;
@property (weak, nonatomic) IBOutlet UILabel *middleLab;
@property (weak, nonatomic) IBOutlet UILabel *bottomLab;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topLabT;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomLabB;

@property (assign, nonatomic) CGFloat topConstantTmp;
@property (assign, nonatomic) CGFloat bottomConstantTmp;

@property (strong, nonatomic) NSIndexPath *idxPth;

@end

@implementation JZChargeHomeCell

- (void)awakeFromNib{
    [super awakeFromNib];
    
    self.layer.borderWidth = 1.0;
    
    self.clipsToBounds = YES;
    self.layer.cornerRadius = 5;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeCollectionCellStyle:) name:@"JZChangeCollectionCellStyle" object:nil];
    
    _topConstantTmp = self.topConst.constant;
    _bottomConstantTmp = self.bottomConst.constant;
}

- (void)changeCollectionCellStyle:(NSNotification *)notify {
    NSNumber *obj = notify.object;
    NSInteger type = [obj integerValue];
    if (type == 1) {
        
        self.userInteractionEnabled = NO;
    } else {
       
        self.userInteractionEnabled = YES;
    }
}

- (void)configCellContent:(NSIndexPath *)idxPth {
    _idxPth = idxPth;
    if (idxPth.section == 0) {
        _middleLab.hidden = YES;
        _topLabT.constant = 10;
        _bottomLabB.constant = 10;
        
        self.topConst.constant = _topConstantTmp + 6;
        self.bottomConst.constant = _bottomConstantTmp - 6;
    } else {
        _middleLab.hidden = NO;
        _topLabT.constant = 5;
        _bottomLabB.constant = 5;
        
        self.topConst.constant = _topConstantTmp;
        self.bottomConst.constant = _bottomConstantTmp;
    }
}

- (void)configCellData:(NSArray *)array {
    if (_idxPth.section == 0) {
        _topLab.text = Format(@"%@",array[_idxPth.row][@"package_name"] ?: @"暂无");
        _bottomLab.text = Format(@"售价：%.2f元",[array[_idxPth.row][@"price"] floatValue]?: 0.00);
    } else if (_idxPth.section == 1) {
        _topLab.text = Format(@"%@",array[_idxPth.row][@"package_name"] ?: @"暂无");
        _middleLab.text = Format(@"售价：%.2f元",[array[_idxPth.row][@"price"] floatValue]?: 0.00);
        _bottomLab.text = Format(@"%@",array[_idxPth.row][@"time"] ?: @"月底失效");
    }
}

@end
